package 极客算法训练营.chapter10;

public class 买卖股票的最佳时机 {
    class Solution {
        public int maxProfit(int[] prices) {
            int count = 0;
            for (int i = 0; i < prices.length;) {
                int benchMark = prices[i];
                int j = i + 1;
                while (j < prices.length && prices[j] > benchMark) {
                    benchMark = prices[j++];
                }
                int currentProfit =  benchMark - prices[i];
                count += currentProfit;
                i = currentProfit == 0 ? i + 1 : j;
            }
            return count;
        }
    }
}
